#define ElemType int

typedef struct ListNode List_Node;

#include "common.h"

int minSubArrayLen(int target, int* nums, int numsSize);

int main()
{
	int target;
	puts("target:");
	scanf("%d", &target);
	int numsSize;
	puts("numsSize:");
	scanf("%d", &numsSize);
	int* nums = calloc(numsSize, sizeof(int));
	for (int i = 0; i < numsSize; i++)
		scanf("%d", nums + i);

	printf("res:%d\n", minSubArrayLen(target, nums, numsSize));
	return 0;
}

int minSubArrayLen(int target, int* nums, int numsSize)
{
	int sum = 0, ri = 0;
	for (int i = 0; i < numsSize; i++) {
		sum += nums[i];
		if (sum >= target) {
			ri = i;
			break;
		}
	}
	if (sum < target)
		return 0;
	int left = 0;
	while (sum - nums[left] >= target)
		sum -= nums[left++];
	int res = ++ri - left;

	for (; ri < numsSize; ri++) {
		sum += nums[ri];
		while (sum - nums[left] >= target)
			sum = sum - nums[left++];
		int cur_res = ri - left + 1;
		if (cur_res < res)
			res = cur_res;
	}

	return res;
}
